﻿using System;
using System.Collections.Generic;
using AMM.CustomClassLibrary;
using AMM.DataAccess.Config;
using AMM.Model;

namespace AMM.Business.Config {
    public class AttachmentProcessor : BaseProcessor {

        private AttachmentRepository _attachmentRepository;

        public AttachmentProcessor() {
            this._attachmentRepository = new AttachmentRepository();
        }

        public Attachment FetchAttachmentById(int attachmentId) {
            try {
                return this._attachmentRepository.FetchAttachmentById(attachmentId);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw this.BuildException("获取指定附件数据失败！");
            }
        }

        public List<Attachment> FetchUnLinkedAttchment() {
            try {
                return this._attachmentRepository.FetchUnLinkedAttchment();
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw this.BuildException("获取附件列表失败！");
            }
        }
        
        public void Insert(Attachment attachment) {
            try {
                this._attachmentRepository.Insert(attachment);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw this.BuildException("插入新附件失败！");
            }
        }

        public void Update(Attachment attachment) {
            try {
                this._attachmentRepository.Update(attachment);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw this.BuildException("更新附件失败！");
            }
        }
    }
}
